<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>十二岭果酒"水果突击"</title>
    <meta http-equiv="X-UA-Compatible" content="IE=5"/>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<meta name="viewport" content="width=320, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui, user-scalable=no,target-densityDpi=super-high-dpi">
	<meta name="renderer" content="webkit">
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="apple-mobile-web-app-status-bar-style" content="black" />
	<meta name="format-detection" content="telphone=no, email=no" />
	<meta name="HandheldFriendly" content="true">
	<meta name="MobileOptimized" content="320">
	<meta name="browsermode" content="application">
	<meta name="x5-page-mode" content="app">
	<meta name="msapplication-tap-highlight" content="no">
	<meta name="format-detection" content="telephone=no">

	<link rel="stylesheet" href="css/style.css">
	<script src="./js/jquery.js"></script>
	<script src="./js/jquery.cookie.js"></script>
	<script src="./js/GSAP/TweenMax.min.js"></script>
	<script src="./js/GSAP/utils/Draggable.min.js"></script>
	<script src="./js/hammer.min.js"></script>
	<script src="./js/jquery.hammer.js"></script>
	<script src="./js/preLoad.js"></script>
	<script>document.write('<script src="./js/common.js?n='+Math.round(Math.random()*999999999)+'"><\/script>');</script>
	<script>


		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return r[2]; return null;
		}
		var _czc = _czc || [];
		_czc.push(["_setAccount", "1256371227"]);

		if(getQueryString('cc')==null){
			location.href = '/biz/12ling_s01e01/game?cc=0051'
		}
	</script>
</head>
<body style="width:100%;hegith:100%;overflow:hidden;">
	<div class="firstload">
		<img src="images/loading_p0.png">	
	</div>
	<div class="siteMain siteGame">
		<div class="mainContent">
			<!-- 种子玩家的结束页 -->
			<div class="msgbox msgOver0 posabs">
				<div class="wrap">
					<div class="close posabs"><img src='images/game_msg_close.png'></div>
					<div class="result posabs">
						<div class="t0">本次游戏得分:<span>000000</span></div>
						<div class="t1">累积总分</div>
						<div class="t2">000000</div>
						<div class="clearboth"></div>
						<div class="t3">进入兑换平台</div>
					</div>
					<img src='images/game_msg_over0.png'>
				</div>
				<div class="shareBtn">
					<img src='images/game_msg_over2.png'>
					分够了，奖品也就有了
				</div>
				<div class="friends">
					<div class="title">朋友帮忙区</div>
					<ul>
						<li>
							暂无数据...
						</li>
					</ul>
				</div>
			</div>
			<!-- 通过好友的链接进来的结束页 -->
			<div class="msgbox msgOver1 posabs">
				<div class="wrap posabs">
					<div class="close posabs"><img src='images/game_msg_close.png'></div>
					<div class="result posabs">
						<div class="t0 t">本次游戏的得分:<span>000000</span></div>
						<div class="t1 t">为你的好友加了:<span>000000</span></div>
						<div class="t2 t">也为自己赢得了:<span>000000</span></div>
						<div class="t3">进入兑换平台</div>
					</div>
					<div class="shareBtn posabs">
						<img src='images/game_msg_over2.png'>
						分够了，奖品也就有了
					</div>
					<img src='images/game_msg_over1.png'>
				</div>
			</div>
			<!-- 教程 -->
			<div class="msgbox msgTips posabs">
				<div class="hand posabs"><img src="images/game_tips_hand_figure.png"></div>
			</div>
			<!-- 游戏内容 -->
			<div class="game">
				<div class="myScore posabs">
					<div class='w posabs'>得分：<span>0</span></div>
					<img src="images/game_score_bg.png">
				</div>
				<div class="myTime1 posabs">
					<div class="line"></div>
				</div>
				<div class="myTime2 posabs"><img src="images/game_timer_clock.png"></div>
				<div class="moon posabs"><img src="images/game_moon_0.png"></div>
				<div class="cloud c0"><img src="images/game_cloud0.png"></div>
				<div class="cloud c1"><img src="images/game_cloud1.png"></div>
				<div class="cloud c2"><img src="images/game_cloud2.png"></div>
				<div class="bird posabs"><img src="images/game_bird.png"></div>
				<ul>
					<li class="p p0" t=2 s="+100"><img src="images/game_item1.png"></li>
					<li class="p p1" t=3 s="+50"><img src="images/game_item2.png"></li>
					<li class="p p2" t=5 s="+30"><img src="images/game_item0.png"></li>
					<li class="p p3" t=10 s="+20"><img src="images/game_item4.png"></li>
					<li class="p p4" t=20 s="+10"><img src="images/game_item5.png"></li>
					<li class="p p5" t=5 s="-50"><img src="images/game_item7.png"></li>
					<li class="p p6" t=5 s="-30"><img src="images/game_item3.png"></li>
					<li class="p p7" t=10 s="-10"><img src="images/game_item8.png"></li>
					<li class="p p8" t=1 s="x1.5"><img src="images/game_item6.png"></li>
				</ul>
				<div class="figure posabs"><img src="images/game_figure.png"></div>
				<div class="footer"></div>
			</div>
		</div>
	</div>
	<div style="display: none"><script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1256371227'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.cnzz.com/z_stat.php%3Fid%3D1256371227' type='text/javascript'%3E%3C/script%3E"));</script></div>

	<!-- <audio style="display:none" id="musicBox" preload="metadata" src="mp3/bg.mp3"> -->
 </body>
</html>

<script>
	var myWxData = new Object();
	myWxData.appId='<%=wechatSign.appId%>';
	myWxData.timestamp='<%=wechatSign.timestamp%>';
	myWxData.nonceStr='<%=wechatSign.nonceStr%>';
	myWxData.signature='<%=wechatSign.signature%>';
	myWxData.hostname = '<%=hostname%>';
	myWxData.instance = "<%=instance%>";
	myWxData.f_instance = "<%=f_instance%>";
	myWxData.collect = <%=collect%>;
	myWxData.done = <%=done%>;
	myWxData._csrf = "<%=_csrf%>";
	myWxData.own = <%=own%>;

	// var myWxData = new Object();
	// myWxData.appId='<%=wechatSign.appId%>';
	// myWxData.timestamp='<%=wechatSign.timestamp%>';
	// myWxData.nonceStr='<%=wechatSign.nonceStr%>';
	// myWxData.signature='<%=wechatSign.signature%>';
	// myWxData.hostname = '<%=hostname%>';
	// myWxData.instance = "<%=instance%>";
	// myWxData.collect = 1;
	// myWxData.done = 0;
	// myWxData._csrf = "<%=_csrf%>";
	// myWxData.own = 1;

	var myScore=0;
	var countDownGameNum=30;
	var countDownGameNumSave=30;
	var countDownBeginNum=0;
	var gameTimer;
	var tipsAnmi = new TimelineLite();
	var figureTop

	// alert(JSON.stringify(myWxData));

	if(myWxData.done==true){
		alert('每天只能玩一次哦！');
		location.href='startup?cc='+$.getUrlParam('cc')+'&instance='+myWxData.instance;
	}
	//加载...
	$(function(){
		var preLoadImgList = new Array('images/game_timer_line.png','images/game_footer.png','images/game_tips_w0.png');
		preLoad(preLoadImgList);

		_czc.push(["_trackEvent", "加载", "游戏资源", "preload", 1]);
	})

	function siteLoaded(){

		/*按钮绑定*/

		//所有弹出框的关闭按钮
		$('.msgbox .close').each(function(){
			$(this).hammer({}).on("tap press pan swipe", function(){
				location.href='startup?cc='+$.getUrlParam('cc')+'&instance='+myWxData.instance;
			})
		})

		//进入兑换平台
		$('.msgOver0 .t3,.msgOver0 .t3').hammer({}).on("tap press pan swipe", function(){
			buttonAnmi($(this));
			_czc.push(["_trackEvent", "进入兑换平台", "游戏资源", "preload", 1]);
			location.href='startup?ac=getPrize&cc='+$.getUrlParam('cc')+'&instance='+myWxData.instance;
		})
		$('.msgOver1 .t3,.msgOver0 .t3').hammer({}).on("tap press pan swipe", function(){
			buttonAnmi($(this));
			_czc.push(["_trackEvent", "进入兑换平台", "游戏资源", "preload", 1]);
			location.href='startup?ac=getPrize&cc='+$.getUrlParam('cc')+'&instance='+myWxData.instance;
		})

		//拖动嫦娥
		Draggable.create($('.game .figure'),{
			type:'x',
			edgeResistance:0.5,
			bounds:$('.game'),
			throwProps:true,
			pointerEvent:function(){
				console.log(this.pointerY);
			}
		});

		//物品和动画设置
		showTips();

		//游戏开始倒数的函数，开始游戏之前，后台需要判断是否可以数，再开始。
		// countBeginDown();

		figureTop=$('.figure').offset().top;
	}
	//自己为自己加分
	function addMyScore(){
		$.ajax({
			type: "POST",
			url:"/biz/12ling_s01e01/addMyScore",
			data:{_csrf:myWxData._csrf, instance:myWxData.instance, score:myScore},
			dataType:'json',
			success: function(data) {
				if(data.success==true){
					if(myWxData.own==true){
						//显示种子玩家的结束页
						total=myWxData.collect+myScore;
						$(".msgOver0 .t0 span").text(myScore);
						$(".msgOver0 .t2").text(total);
						$(".msgOver0").fadeIn(300);

						_czc.push(["_trackEvent", "自己加分", "ajax", "好友", 1]);
					}else{
						_czc.push(["_trackEvent", "好友加分", "ajax", "自己", 1]);
						//显示通过好友的链接进来的结束页
						$(".msgOver1 .t0 span").text(myScore);
						$(".msgOver1 .t1 span").text(myScore);
						$(".msgOver1 .t2 span").text(myScore);
						$(".msgOver1").fadeIn(300);
					}
				}else{
					alert(data.msg);
				}
			},
			beforeSend: function(){
				$(".ajaxLoading").show();
			},
			complete: function(){
				// alert(JSON.stringify(data));
				$(".ajaxLoading").hide();
			}
		});
	}
	//为别人加分
	function addScore(){
		$.ajax({
			type: "POST",
			url:"/biz/12ling_s01e01/addScore",
			data:{_csrf:myWxData._csrf, f_instance:myWxData.f_instance, score:myScore},
			dataType:'json',
			success: function(data) {
				if(data.success==true){
					$(".msgOver1 .t0 span").text(myScore);
					$(".msgOver1 .t1 span").text(myScore);
					$(".msgOver1 .t2 span").text(myScore);
					$(".msgOver1").fadeIn(300);

					_czc.push(["_trackEvent", "为别人加分", "ajax", "加分", 1]);
				}else{
					alert(data.msg);
				}
			},
			beforeSend: function(){
				// $(".ajaxLoading").show();
			},
			complete: function(){
				// alert(JSON.stringify(data));
				// $(".ajaxLoading").hide();
			}
		});
	}
	//游戏设置
	function showTips(){
		$('.msgTips').show(0);
		kW=$(window).width();
		kH=$(window).height();

		//背景动画
		// TweenMax.to($('.c0'),50,{x:kW, ease:Linear.easeNone, yoyo:true, repeat:-1});
		// TweenMax.to($('.c1'),60,{x:-kW, ease:Linear.easeNone, yoyo:true, repeat:-1});
		// TweenMax.to($('.c2'),60,{x:-kW, ease:Linear.easeNone, yoyo:true, repeat:-1});
		// TweenMax.to($('.bird'),2,{y:"+=50%", ease:Linear.easeNone, yoyo:true, repeat:-1});

		//人物和手设定居中位置
		toX=(kW-$('.figure').width())/2;
		// TweenMax.to($('.figure, .msgTips .hand'),0,{x:toX});

		//材料设定教程时的位置
		$('.game ul li').each(function(){
			l=$('.game ul li').length;
			n=$('.game ul li').index($(this))+0.5;
			obj=$(this);
			// toX=(kW-obj.width())*Math.random();
			// toY=($('.figure').offset().top-obj.height())*Math.random();
			toX=(kW-obj.width())/l*n;
			toY=-obj.height();
			TweenMax.to(obj,0,{x:toX, y:toY})
			t=4*Math.random()+2;
			t2=2*Math.random();
			// TweenMax.to(obj,t,{y:kH+obj.height(), ease:Linear.easeNone, repeat:-1, yoyo:false, delay:t2})
		})

		//教程动画
		toX=kW-$('.figure, .msgTips .hand').width();
		tipsAnmi
			// .from($('.msgTips .hand'),1,{x:0, scale:4, autoAlpha:0, ease:Expo.easeInOut},'+=1')
			// .to($('.msgTips .hand'),0.2,{rotation:15, repeat:3, yoyo:true, ease:Expo.easeInOut, transformOrigin:"center top"},'-=0.3')
			.to($('.figure, .msgTips .hand'),2,{x:toX, ease:Expo.easeInOut, repeat:-1, yoyo:true})
		;

		//点击教程动画开始游戏
		$('.msgTips').hammer({}).on("tap", function(){

			_czc.push(["_trackEvent", "开始游戏", "ajax", "gamestart", 1]);
			TweenMax.killTweensOf($('.game ul li'));
			tipsAnmi.kill();
			$('.game ul li').each(function(){
				obj=$(this);
				toY=-obj.height();
				TweenMax.to(obj,0,{y:toY})
			})
			TweenMax.to($(".myTime1 .line"),1,{x:'-100%', ease:Linear.easeNone});
			$(this).fadeOut(0);
			// setTimeout(countBeginDown,500);
			setTimeout(countGameDown,100);
			setTimeout(startAitem,100);
		})
	}

	//击中物体一个材料
	function hitAitem(obj){
		//标志被击中
		obj.attr('hit',1);
		//出现次数减1
		t=Number(obj.attr('t'));
		obj.attr('t',t-1);
		//获取材料分值
		s=obj.attr('s')
		if(s == 'x1.5'){
			myScore*=1.5;
		}else{
			myScore+=Number(s);
		}
		myScore = myScore<0 ? 0 : myScore;
		$('.myScore span').text(myScore.toFixed(0));
		//出现分数显示
		$('.figure').append('<span>'+s+'</span>');
		TweenMax.to($('.figure span:last'),0.3,{y:'-=100%', ease:Linear.easeNone, onComplete:removeScoreSpan, onCompleteParams:[$('.figure span:last')]});

		//材料飞向姑娘
		toX=$('.figure').offset().left+$('.figure').width()/4;
		toY=$('.figure').offset().top+$('.figure').height()/2;
		TweenMax.killTweensOf(obj);
		// TweenMax.to(obj,0.1,{x:toX, y:toY, scale:0, autoAlpha:1, ease:Linear.easeNone, onComplete:ObjMoved, onCompleteParams:[obj]});
		TweenMax.to(obj,0,{autoAlpha:0, ease:Linear.easeNone, onComplete:ObjMoved, onCompleteParams:[obj]});
	}
	//删除分数顶标
	function removeScoreSpan(obj){
		obj.remove();

	}
	//驱动一个材料
	function startAitem(){
		dTime=500;
		l1=$('.game ul li[t!=0]').length;
		l2=$('.game ul li[t!=0][moving!=1]').length;
		n=Math.floor(Math.random()*l2);
		obj=$($('.game ul li[t!=0][moving!=1]')[n]);

		// console.log(l1+" : "+l2);

		if(l2>0){
			setDqPosition(obj);
			gameTimer = setTimeout(startAitem,dTime)
			return true;
		}else if(l1>0){
			gameTimer = setTimeout(startAitem,dTime)
			return false;
		}

		console.log('结束');
	}
	//材料位置
	function setDqPosition(obj){
		obj.attr('moving',1)
		kW=$(window).width();
		kH=$(window).height();
		dir=Math.random()*2 >1 ? 1 : -1;
		div=kW*0.3;
		toX0=Math.random()*(kW-obj.width());
		toY0=-obj.height();
		TweenMax.to(obj,0,{x:toX0,y:toY0,scale:1,autoAlpha:1})

		toX1=toX0+dir*div;
		if(toX1 > kW-obj.width() || toX1 < 0){
			// toX1 = kW-obj.width();
			toX1 = toX0-dir*div;
		}
		toY1=kH*Math.random();
		toX2=toX0;
		toY2=kH;
		timer=Math.random()*1+1;
		// timer=1.5;
		// TweenMax.to(obj,timer,{y:toY, ease:Linear.easeNone, onUpdate:checkHitTest, onUpdateParams:[obj], onComplete:ObjMoved, onCompleteParams:[obj]});
		TweenMax.to(obj,timer,{bezier:{type:'thru', values:[{x:toX0,y:toY0},{x:toX1,y:toY1},{x:toX2,y:toY2}]}, ease:Linear.easeNone, onUpdate:checkHitTest, onUpdateParams:[obj], onComplete:ObjMoved, onCompleteParams:[obj]});
	}
	//检查碰撞
	function checkHitTest(obj){
		h0=obj.offset().top+obj.height();
		if(obj.attr('hit')!=1 && h0>figureTop){
			re = Draggable.hitTest(obj,$('.game .figure'),'50%');
			if(re == true){
				hitAitem(obj);
			}
		}
	}
	//材料完成一次下跌
	function ObjMoved(obj){
		obj.attr('hit',0);
		obj.attr('moving',0)
	}
	//开始倒计时
	function countBeginDown(){
		if(countDownBeginNum>=0){
			$(".game .msgBegin .wrap").text(countDownBeginNum);
			countDownBeginNum--;
			setTimeout(countBeginDown,1000);
		}else{
			$(".game .msgBegin").fadeOut(300);
			startAitem();
			countGameDown();
			// musicBox.play();
		}
	}
	//游戏倒计时
	function countGameDown(){
		$('.testLayer').text(countDownGameNum);
		if(countDownGameNum>=0){
			per=(countDownGameNumSave-countDownGameNum)/countDownGameNumSave;
			per2=countDownGameNum/countDownGameNumSave;
			toX='-'+(per2*100)+'%'
			// $(".myTime2").text('时间：'+countDownGameNum);
			TweenMax.to($(".myTime1 .line"),1,{x:toX, ease:Linear.easeNone});
			countDownGameNum--;
			setTimeout(countGameDown,1000);
		}else{
			TweenMax.killChildTweensOf($('.game ul') ,true);
			clearTimeout(gameTimer);

			_czc.push(["_trackEvent", "游戏结束", "over", "结束", 1]);
			//数据提交
			if(myWxData.own == false){
				//自己和好友一起加分
				addScore();
			}else{
				//自己加分
				addMyScore();
			}
		}
	}

	//获取我的好友信息
	getFriends();
	function getFriends(){
		$.ajax({
			type: "POST",
			url:"/biz/12ling_s01e01/getFriends",
			data:{_csrf:myWxData._csrf,instance:myWxData.instance},
			dataType:'json',
			success: function(data) {
				if(data.success==true){
					// alert(JSON.stringify(data));
					arr=data.data;
					html='';
					for(i in arr){
						d=arr[i];
						html+='<li><div class="head"><img src="'+d[1]+'"></div><div class="word">你的好友<span class="s0">'+d[0]+'</span>帮你赢得<span class="s1">'+d[2]+'</span>分</div></li>'
					 }
					 $('.msgOver0 .friends ul').html(html);
				}else{
					alert(data.msg);
				}
			},
			beforeSend: function(){
				// $(".ajaxLoading").show();
			},
			complete: function(data){
				// $(".ajaxLoading").hide();
			}
		});
	}

	//禁止IOS回弹;
	document.addEventListener("touchmove", function(evt){
		// evt.preventDefault();
		// alert(JSON.stringify(evt));
		// console.log(11)
		// $('.testLayer').text(JSON.stringify(evt));
	}, true);


</script>
